function [fo] = make_filename(path);
% function nextname finds the next valid name on the specified path
% This works as follows:
% the filename is in datac format: ddmmmyyl.ext
% ext is always pbm (? change later to better extension ?)
% dd = numeric day, leading 0
% mmm = month in letter format jan feb mar apr may jun jul aug sep oct nov dec
% yy = year (99,00, etc).
% l = letter for cell identification
%
% first get the date and generate the base filename parts.
%

fo = [];
if(nargin ~= 1)
   fprintf('ERROR nextname.m requires path argument\n');
   return;
end;
dn = date;
base = lower([dn(1:2) dn(4:6) dn(10:11)]); % base name
lettera = 97; % base letter is 97 decimal, corresponding to ascii 'a' (lowercase)
for i = 0:25 % only the letters
   fn = [base char(lettera+i) '.pbm'];
   ft = fullfile(path, fn); % make full filename
   if(~(exist(ft) == 2)) % file does not exist, so make it
      fo = fn;
      if(i > 0)
         hfn = [base char(lettera+i-1) '.pbm']; % get the header hfile from the previous file in series
         hft = fullfile(path, hfn); % we use this information to initialize the initial header information
         if(exist(hft) == 0) % no file, 
            return;
         end;
         return;
      else
         return; % i is 0, 'a' file, just do it
      end;
      
   end;
end;
QueMessage('nextfile.m is out of file names for this date\n');
fo = [];
return;

